<!DOCTYPE html>
<head>
  <title>creat_app</title>
  <meta charset="utf-8">

  <link type="text/css" rel="stylesheet" href="../highlight/styles/common.css">
  <link rel="alternate stylesheet" title="Zenburn" href="../highlight/styles/zenburn.css">
  <link rel="alternate stylesheet" title="Pojoaque" href="../highlight/styles/pojoaque.css">
  <link rel="alternate stylesheet" title="MonoBlue" href="../highlight/styles/mono-blue.css">
  <script src="../highlight/styleswitcher.js" type="text/javascript"></script>
<body>

<div id="styleswitcher"></div>

<table id="autotest">
  <tr>
    <td class="php">
<pre><code>
	/**
	 * 初始化应用程序
	 */
	public static function creat_app() {
		return self::load_sys_class('application');
	}
</code></pre>
    </td>
  </tr>
  <tr>
    <td class="php">
<pre><code>
	/**
	 * 加载系统类方法
	 * @param string $classname 类名
	 * @param string $path 扩展地址
	 * @param intger $initialize 是否初始化
	 */
	public static function load_sys_class($classname, $path = '', $initialize = 1) {
			return self::_load_class($classname, $path, $initialize);
	}
</code></pre>
    </td>
  </tr>
  <tr>
  	<td class="php">
<pre><code>
	//PHPCMS框架路径
	define('PC_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

	/**
	 * 加载类文件函数
	 * @param string $classname 类名
	 * @param string $path 扩展地址
	 * @param intger $initialize 是否初始化
	 */
	private static function _load_class($classname, $path = '', $initialize = 1) {
		static $classes = array();
		if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'classes';

		$key = md5($path.$classname);
		if (isset($classes[$key])) {
			if (!empty($classes[$key])) {
				return $classes[$key];
			} else {
				return true;
			}
		}
		if (file_exists(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
			include PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php';
			$name = $classname;
			if ($my_path = self::my_path(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
				include $my_path;
				$name = 'MY_'.$classname;
			}
			if ($initialize) {
				$classes[$key] = new $name;
			} else {
				$classes[$key] = true;
			}
			return $classes[$key];
		} else {
			return false;
		}
	}
</code></pre>
    </td>
  </tr>
  <tr>
  	<td class="php">
<pre><code>
  	/**
	 * 是否有自己的扩展文件
	 * @param string $filepath 路径
	 */
	public static function my_path($filepath) {
		$path = pathinfo($filepath);
		if (file_exists($path['dirname'].DIRECTORY_SEPARATOR.'MY_'.$path['basename'])) {
			return $path['dirname'].DIRECTORY_SEPARATOR.'MY_'.$path['basename'];
		} else {
			return false;
		}
	}
</code></pre>
    </td>
  </tr>
</table>
